<?php

namespace app\models;

use app\models\common\admin\log\CommonActionLog;
use Yii;

/**
 * This is the model class for table "{{%topic}}".
 *
 * @property integer $id
 * @property integer $store_id
 * @property integer $type
 * @property string $title
 * @property string $sub_title
 * @property string $cover_pic
 * @property string $content
 * @property integer $read_count
 * @property integer $virtual_read_count
 * @property integer $layout
 * @property integer $sort
 * @property integer $agree_count
 * @property integer $virtual_agree_count
 * @property integer $virtual_favorite_count
 * @property integer $addtime
 * @property integer $is_chosen
 * @property integer $is_delete
 * @property string $qrcode_pic
 */
class Dynamic extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%dynamic}}';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['store_id','url','pic_list'], 'required'],
            [['store_id',  'sort', 'addtime', 'is_chosen', 'is_delete'], 'integer'],
            [['title'], 'string', 'max' => 255],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'store_id' => 'Store ID',
            'title' => '标题',
            'pic_list' => '封面图片',
            'sort' => '排序：升序',
            'addtime' => 'Addtime',
            'is_chosen' => 'Is Chosen',
            'is_delete' => 'Is Delete',
            'url' => '外部链接url'
        ];
    }

    public function afterSave($insert, $changedAttributes)
    {
        $data = $insert ? json_encode($this->attributes) : json_encode($changedAttributes);
        CommonActionLog::storeActionLog('', $insert, $this->is_delete, $data, $this->id);
    }
}
